package cn.smile.controller.admin;

import cn.smile.util.FIleUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.smile.bean.Result;

/**
 * 公用的上传类
 */
@Slf4j
@RequestMapping("/admin/upload")
@Controller
public class AdminUploadController {

    @Value("${web.upload.photo.suffix}")
    private String uploadPhotoSuffix;

    @Value("${web.upload.photo.maxsize}")
    private long uploadPhotoMaxSize;

    @Value("${web.upload.photo.path}")
    private String uploadPhotoPath;//文件保存位置

    /**
     * 图片统一上传类
     */
    @RequestMapping(value = "/upload_photo", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> uploadPhoto(@RequestParam(name = "photo") MultipartFile photo) {
        return FIleUtil.uploadPhoto(photo, uploadPhotoSuffix, uploadPhotoMaxSize, uploadPhotoPath);
    }
}
